<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!-- <!DOCTYPE html> -->
<html lang="en">
<head>
<meta charset="UTF-8">
<title>软件分享系统</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/jquery-3.3.1.js"></script>
<!-- <script src="js/bootstrap.min.js"></script> -->
<style>
body {
	background: url(./img/bg.jpeg) no-repeat;
}

.box {
	position: absolute;
	top: 17%;
	width: 100%;
	color: #fff !important;
}

.mg {
	margin: 25px 0;
}

.mg1 {
	margin-left: 20%;
}
</style>
</head>
<body>

	<div class="box">
		<div class="row">
			<div class="col-md-8"></div>
			<div class="col-md-2">
				<h1 class="text-center mg">注   册</h1>

				<div class="form-group">
					<label for="username">用户名</label> <input type="text"
						class="form-control" id="username" placeholder="请输入用户名">
				</div>
				<div class="form-group">
					<label for="password">密码</label> <input type="password"
						class="form-control" id="password" placeholder="请输入密码">
				</div>
				<div class="form-group">
					<label for="realname">姓名</label> <input type="text"
															class="form-control" id="realname" placeholder="请输入姓名">
				</div>
				<div class="form-group">
					<label for="phone">手机号码</label> <input type="text"
															class="form-control" id="phone" placeholder="请输入手机号码">
				</div>
				<div class="form-group">
					<label for="password">用户类型</label> <input type="text" value="普通用户" readonly="readonly"
															class="form-control" id="userType" placeholder="请输入用户类型">
				</div>
				<div class="form-group">
					<label for="password">性别</label>
						<select id="sex" name="sex" class="form-control">
							    <option value="">该选择性别</option>
							    <option value="男">男</option>
							    <option value="女">女</option>
							</select>
				</div>
				
				<button type="submit" class="btn btn-primary mg1" onclick="login()">确定</button>
				<a href="./login.jsp"><button type="submit" class="btn btn-default mg1">返回</button></a>

			</div>
			<div class="col-md-2"></div>
		</div>
	</div>
</body>
<script>
	function login() {
        var username = $("#username").val();
        var password = $("#password").val();
        var realname = $("#realname").val();
        var phone = $("#phone").val();
        var userType = $("#userType").val();
        var sex = $("#sex").val();

		if (username == '') {
			alert('用户名不能为空');
			return false;
		}
		if (password == '') {
			alert('密码不能为空');
			return false;
		}

		$.ajax({
			url : "/rjfxsys/user?method=addUser",
			data : {
				username : username,
				password : password,
				realname : realname,
				phone : phone,
				userType : userType,
				sex : sex
			},
			type : "post",
			success : function(data) {
				console.log(data);
				data = JSON.parse(data);
				if (data.msg == "ok") {
					alert("注册成功！");
					location.href = "login.jsp"
				} else {
					alert('注册失败！'
							+ (data.handle != 'undefind' ? data.handle : ""));
				}
			}
		})
	}
	//点击图片切换验证码
	$("#vcodeImg").click(function(){
		this.src="/rjfxsys/registration?method=GetVcode&t="+new Date().getTime();
	});
</script>
</html>